﻿Imports System.Data.SqlClient

Public Class clsKardex
    Private mintIdBoleto As Integer
    Private mintIdAutobus As Integer
    Private mstrSerie As String
    Private mdblInicial As Double
    Private mdblFinal As Double
    Private mdblTotalBoletos As Double
    Public Property IdBoleto() As Integer
        Get
            Return mintIdBoleto
        End Get
        Set(ByVal value As Integer)
            mintIdBoleto = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property
    Public Property Serie() As String
        Get
            Return mstrSerie
        End Get
        Set(ByVal value As String)
            mstrSerie = value
        End Set
    End Property
    Public Property Inicial() As Double
        Get
            Return mdblInicial
        End Get
        Set(ByVal value As Double)
            mdblInicial = value
        End Set
    End Property
    Public Property Final() As Double
        Get
            Return mdblFinal
        End Get
        Set(ByVal value As Double)
            mdblFinal = value
        End Set
    End Property
    Public Property TotalBoletos() As Double
        Get
            Return mdblTotalBoletos
        End Get
        Set(ByVal value As Double)
            mdblTotalBoletos = value
        End Set
    End Property

    Public Sub New()
        mintIdAutobus = 0
        mstrSerie = ""
        mdblInicial = 0
        mdblFinal = 0
        mdblTotalBoletos = 0

    End Sub
    Public Sub Borrar()

        Call SetSqlCitra("Delete From KARDEX Where cidboleto = " & IdBoleto)

    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Kardex (" & _
                            "IdAutobus," & _
                            "Serie," & _
                            "Inicial," & _
                            "Final," & _
                            "TotalBoletos)" & _
                            "VALUES (" & _
                            "@IdAutobus," & _
                            "@Serie," & _
                            "@Inicial," & _
                            "@Final," & _
                            "@TotalBoletos)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)
        Command.Parameters.AddWithValue("IdBoleto", mintIdBoleto)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("Serie", mstrSerie)
        Command.Parameters.AddWithValue("Inicial", mdblInicial)
        Command.Parameters.AddWithValue("Final", mdblFinal)
        Command.Parameters.AddWithValue("TotalBoletos", mdblTotalBoletos)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Liquidacion ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update Kardex Set " & _
                    "Serie=@Serie," & _
                    "Incial=@Incial," & _
                    "Final=@Final," & _
                    "Total=@Total," & _
                     "Where IdBoleto=@IdBoleto"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("IdBoleto", mintIdBoleto)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("Serie", mstrSerie)
        Command.Parameters.AddWithValue("Inicial", mdblInicial)
        Command.Parameters.AddWithValue("Final", mdblFinal)
        Command.Parameters.AddWithValue("TotalBoletos", mdblTotalBoletos)
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub

End Class
